/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package be.fedict.drupaltest.parts;

import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

/**
 * Drupal installation wizard site info page.
 * 
 * @author Bart Hanssens
 */
public class BasePage {
    /**
     * Get the option element by name
     * 
     * @param select select list element
     * @param text name of the option
     * @return element or null
     */
    public static WebElement getOptionElement(WebElement select, String text) {
        Select s = new Select(select);
        for(WebElement el : s.getOptions()) {
            if (el.getText().compareToIgnoreCase(text) == 0) {
                return el;
            }
        }
        return null;
    }
    
    /**
     * Select an option by name
     * 
     * @param el select list element
     * @param text option to select
     */
    public static void selectOption(WebElement el, String text) {
        Select s = new Select(el);
        s.deselectAll();
        s.selectByVisibleText(text);    
    }
    
    /**
     * Get a specific radio element by name
     * 
     * @param radios list of radio button elements
     * @param value value of the radion button
     * @return element or null 
     */
    public static WebElement getRadioElement(List<WebElement> radios, String value) {
        for(WebElement el : radios) {
            if (el.getAttribute("value").equalsIgnoreCase(value)) {
                return el;
            }
        }
        return null;
    }
}
